package ssm.spring.ioc_02;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * description: 生命周期方法、作用域
 */

//@Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON)  //单例 默认值
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)  //多例
@Component  // 必须要配合bean标记注解才能扫描到
public class JavaBean {

    //周期方法命名随意  public void 没有形参
    @PostConstruct
    public void init(){
        System.out.println("JavaBean.init");
    }

    // 多例模式下，IOC不会管理销毁方法
    @PreDestroy
    public void destroy(){
        System.out.println("JavaBean.destroy");
    }
}
